Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
How add two values[1,2 elements] and verify its equal to result[3 element]

I need to verify if the sum of two elements is equal to the result shown on the UI. Below is the html structure for the three elements and need to do the calculation on the h1 tags. enter image description here

Below is the code I am trying to execute but nothing comes up in the test. The test runs and passes but nothing in the body.

it.only(' Verify Sum Of Active and Paused Jobs is Equal To Total Jobs Count ', () => {
    function activejobnumber() {
    return cy.get('[data-cy="jobSummaryActiveJobsStatTitle"]>h1')
    .invoke('text').then(parseInt).as('actnum');
      
    }

    function pausedjobnumber() {
      return cy.get('[data-cy="jobSummaryPausedJobsStatTitle"] > h1')
     .invoke('text').then(parseInt).as('pasnum');
      
    }
    function add() {
      const totaljobs = activejobnumber() + pausedjobnumber();
      cy.log(totaljobs);
    }
  });

Also, if someone could point out why it isn't working, would really appreciate it.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Using functions to encapsulate each number is fine, but remember that commands inside are still asynchronous, and they are not returning numbers, they are returning Chainers.

If you did it without functions, this is what it would look like

cy.get('[data-cy="jobSummaryActiveJobsStatTitle"]>h1')
  .invoke('text').then(parseInt).as('actnum')
  .then(actnum => {

    cy.get('[data-cy="jobSummaryPausedJobsStatTitle"] > h1')
      .invoke('text').then(parseInt).as('pasnum')
      then(pasnum => {
 
        const totaljobs = actnum + pasnum
        cy.log(totaljobs)
      })
  })

so with functions you need to repeat that pattern

function add() {
   activejobnumber().then(actnum => {
     pausedjobnumber().then(pasnum => {
       const totaljobs = actnum + pasnum;
       cy.log(totaljobs);
     })
  })
}

or take advantage of the alias for each number

function add() {
  activejobnumber()
  pausedjobnumber()

  // wait for above async calls to finish
  cy.then(function() {          
    const totaljobs = this.actnum + this.pasnum;
    cy.log(totaljobs);
  })
}
about 4 years ago · Santiago Trujillo Relatório

0

You can directly invoke text, convert them to numbers and add it like this:

cy.get('[data-cy="jobSummaryActiveJobsStatTitle"]>h1')
  .invoke('text')
  .then((actnum) => {
    cy.get('[data-cy="jobSummaryPausedJobsStatTitle"] > h1')
      .invoke('text')
      .then((pasnum) => {
        //Adding + converts string to number
        const totaljobs = +actnum + +pasnum
        cy.log(totaljobs)
      })
  })
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda